package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.query.resourse.ResourceInsertQuery;
import com.wsoft.system.query.resourse.ResourceListQuery;
import com.wsoft.system.query.resourse.ResourceUpdateQuery;
import com.wsoft.system.service.ISysResourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 后台资源表 前端控制器
 * @author juiet
 * @since 2024年11月18日 17:13:44
 */
@RestController
@Tag(name = "资源管理")
@RequestMapping("/sys/resource")
public class SysResourceController {
    @Resource
    private ISysResourceService resourceService;

    @Operation(summary = "新增资源")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ResourceInsertQuery query) {
        boolean b = resourceService.insert(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "修改资源")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ResourceUpdateQuery query) {
        boolean b = resourceService.update(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "删除资源")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = resourceService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "获取资源详情")
    @GetMapping("/get")
    public ResponseResult getResource(@RequestParam("id") Long id) {
        return ResponseResult.success(resourceService.getResource(id));
    }
    @Operation(summary = "获取资源列表")
    @PostMapping("/list")
    public ResponseResult listResource(@RequestBody @Valid ResourceListQuery query) {
        return ResponseResult.success((resourceService.listResource(query)));
    }
}
